Repository navigation
feat(github-ci): write the #8580 GitHub mirror from the webhook Worker - #8604
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 22 minutes. View limit details
Walkthrough
Pre-merge checks:
|
|
@codex review Increment 1 of #8580: the github-ci Worker now upserts the GitHub mirror (issues / PRs / comment touches + per-repo staleness meta) into fleet-queue Turso from webhook deliveries. Please review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7bcace8a8a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…deleted notes (#8580) Codex P2s on PR #8604: webhook delivery order can differ from event order, so issue/PR upserts now refuse a snapshot whose gh_updated_at is older than the stored row (equal re-applies; NULL stored accepts). issue_comment deletions never assign the latest-agent-note pointer, and a stored pointer naming the deleted comment is cleared. Tests: vitest 41/41 (2 new), tsc clean, prettier clean.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4031dbc64f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…lete mirror row on issues deleted (#8580)
|
@codex review Both P2 findings from the 4031dbc review are fixed in f9eff4d (replies on each thread; all four review threads on this PR are now resolved):
Verified on the laptop: vitest 43/43 pass, |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f9eff4dc97
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Round 3 on PR #8604, head ae3752a. The count-regression P2 from the f9eff4d review is fixed (reply on its thread; thread resolved): comment counts are versioned by the carrying object's |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae3752a790
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| gh_updated_at = CASE | ||
| WHEN ? IS NULL OR gh_updated_at IS NULL | ||
| OR ? >= gh_updated_at | ||
| THEN COALESCE(?, gh_updated_at) ELSE gh_updated_at END, |
There was a problem hiding this comment.
Separate the comment-count version from the snapshot version
When a newer comment delivery arrives before an older issue/PR snapshot, this advances gh_updated_at without updating any non-comment fields. For example, if a close event at t1 is delayed until after a comment at t2, the comment preserves the stored open state but advances its version to t2; the conflict guards in mirrorIssueEvent and mirrorPrEvent then reject the t1 close snapshot, leaving the mirror incorrectly open until another full snapshot or backfill. A comment-seeded row can similarly reject its first full snapshot and retain NULL fields. Store the count version separately and guard snapshot fields against the last full snapshot's version, or apply the corresponding snapshot fields before advancing their version.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 79c4c7f (this reply was missed when the fix landed — posting it now for the thread record): the count carries its own version column (comments_gh_updated_at), separate from the snapshot version. Comment events guard and advance only the count version; snapshot upserts guard snapshot fields against gh_updated_at and move the count only under the count-version guard, so a newer comment landing before a delayed older snapshot (e.g. a close) no longer makes that snapshot fail the upsert guard. Verified at the time: worker suite 45/45, tsc + prettier clean, and a behavioral SQLite simulation of the exact SQL (comment-first seeding, delayed close applies without regressing the count, stale deliveries refused).
…apshot version (#8580) Codex P2 on PR #8604: the comment update advanced gh_updated_at, so a newer comment landing before a delayed older snapshot (e.g. a close) made that snapshot fail the upsert guard and left the mirror stale until backfill. The count now carries its own version column (comments_gh_updated_at): comment events guard and advance only it, snapshot upserts guard snapshot fields against gh_updated_at and move the count only under the count-version guard. Existing databases gain the column via an idempotent pragma_table_info probe + ALTER in mirrorBatch. Verified: worker suite 45/45, tsc + prettier clean, and a behavioral SQLite simulation of the exact SQL (comment-first seeding, delayed close applies without regressing the count, stale deliveries refused).
|
Fixed in 79c4c7f (the "Separate the comment-count version from the snapshot version" P2): the count now carries its own version column, Verified: full worker suite 45/45 (new guard-shape test for the upsert count CASE; the worker pipeline-call counts updated for the DDL batch + probe), tsc clean, prettier clean, and a behavioral SQLite simulation of the exact SQL: comment at t2 seeds a row (count 5, snapshot version untouched), a delayed close snapshot at t1 then applies its state without regressing the count, an older comment at t0 cannot regress it either, a newer snapshot at t3 advances both versions, and a stale snapshot is refused whole. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79c4c7fe81
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sql: "DELETE FROM github_mirror_issues WHERE repo = ? AND number = ?", | ||
| args: [tArg(repo), iArg(num(issue, "number"))], |
There was a problem hiding this comment.
Preserve a tombstone when deleting a mirrored issue
If an issue-deletion delivery arrives before a delayed pre-deletion snapshot or comment, this DELETE removes all evidence that the issue was deleted. Although the deletion delivery itself is now handled, the subsequent snapshot INSERT recreates the issue, and mirrorCommentEvent can likewise recreate it through its unconditional seed INSERT. The deleted issue then remains in the live mirror until reconciliation. Preserve a deletion marker and consult it in both insertion paths, as the existing projector does through deletionBlocks in pm-stack/projector/src/projector.ts:202–214,230.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 83e4984: the issues "deleted" handler now also writes a tombstone (new table github_mirror_tombstones: repo, number, and the deleted issue's gh_updated_at), following the projector's deletionBlocks precedent. Every insertion path carries the guard in SQL — the issue and PR snapshot upserts became INSERT ... SELECT ... WHERE NOT EXISTS (tombstone at or after the incoming source version), and the comment seed INSERT and comment UPDATE carry the same NOT EXISTS guard — so a delayed pre-deletion snapshot or comment is absorbed atomically with the write it would have made, and a strictly newer snapshot (a genuinely recreated issue) still passes. The pure rule is exported as deletionBlocks with unit tests for its truth table (oracle: the projector rule, #6782). Verified: vitest 48/48 (rule tests, tombstone-write test, guard-presence tests for both insertion paths; the comment-count bind count updated for the guard's two extra version binds), tsc + prettier clean, and a behavioral SQLite simulation of the exact guarded upsert: a pre-deletion snapshot inserts 0 rows, a newer snapshot is admitted.
…issue (#8580) Codex P2 on PR #8604: the issues deleted handler removed the mirror row outright, so a delayed pre-deletion snapshot (or a comment seed) arriving after the deletion recreated the issue in the live mirror until reconciliation. The deletion now also writes a tombstone (github_mirror_tombstones: repo, number, the deleted issue gh_updated_at), and every insertion path — the issue and PR snapshot upserts, the comment seed, and the comment update — carries the guard in SQL (NOT EXISTS over the tombstone with the incoming source version), the mirror spelling of the projector deletionBlocks rule. A strictly newer snapshot passes, so a genuinely recreated issue is not blocked. Verified: vitest 48/48 (new deletionBlocks rule tests, tombstone write test, guard-presence tests for both insertion paths), tsc + prettier clean, and a behavioral SQLite simulation of the exact guarded upsert (pre-deletion snapshot absorbed, newer snapshot admitted).
|
@codex review New head 83e4984 fixes the last undispositioned P2 (tombstone on mirrored-issue deletion, thread 4537206918) and the count-version-separation thread (4536544037, fixed in 79c4c7f) now carries its fix reply. Re-requesting review of the current head. (Queue worker lane code-c, task 14908.) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83e498454e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sql: "DELETE FROM github_mirror_issues WHERE repo = ? AND number = ?", | ||
| args: [tArg(repo), iArg(num(issue, "number"))], |
There was a problem hiding this comment.
Make issue deletion atomic with its tombstone write
When a deletion and a delayed snapshot or comment are processed concurrently, the delayed delivery can insert the issue after this DELETE but before the tombstone INSERT. Turso.batch sends separate execute requests without a transaction (src/turso.ts:45–51), so sharing a pipeline does not close that window. The subsequent tombstone prevents future writes but does not remove the resurrected row, leaving a deleted issue in the live mirror. Unlike the earlier missing-tombstone issue, the fresh evidence here is the nontransactional DELETE-before-marker ordering. Write the deletion and marker atomically, or establish the marker before deleting the row.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c4327f3: the deletion batch now writes the tombstone BEFORE the DELETE. Once the marker lands, every insertion path is guard-blocked (TOMBSTONE_GUARD_SQL), and the DELETE that follows removes any row a delayed delivery inserted before the marker existed — the DELETE-then-marker window is closed without needing a transaction. A new test (the tombstone is written before the row deletion) pins the statement order in the captured pipeline. Worker suite 49/49, tsc clean. (Queue worker lane code-c, task 14908.)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83e498454e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| await mirrorBatch(env, "issues", repo, [ | ||
| { | ||
| sql: "DELETE FROM github_mirror_issues WHERE repo = ? AND number = ?", | ||
| args: [tArg(repo), iArg(num(issue, "number"))], |
There was a problem hiding this comment.
Make the row deletion and tombstone write atomic
When a deletion and an older snapshot/comment delivery execute concurrently, the new DELETE-first sequence still allows resurrection: the older delivery can insert after the DELETE but before the tombstone exists. The subsequent tombstone INSERT leaves that row in place, and future guarded writes cannot remove it. Turso.batch sends individual execute requests without BEGIN/COMMIT (src/turso.ts), so putting both statements in one pipeline does not make them atomic. Write the tombstone before deleting the row, or execute both operations in a transaction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c4327f3: the deletion batch now writes the tombstone BEFORE the DELETE. Once the marker lands, every insertion path is guard-blocked (TOMBSTONE_GUARD_SQL), and the DELETE that follows removes any row a delayed delivery inserted before the marker existed — the DELETE-then-marker window is closed without needing a transaction. A new test (the tombstone is written before the row deletion) pins the statement order in the captured pipeline. Worker suite 49/49, tsc clean. (Queue worker lane code-c, task 14908.)
…ed issue (#8580) Codex P2 x2 on PR #8604: Turso.batch is a sequence of separate executes, not a transaction, so DELETE-then-marker left a window where a delayed pre-deletion delivery could insert after the DELETE and be left in place by the later marker. The deletion batch now writes the tombstone first (guard blocks every later insert) and deletes second (removing any row inserted before the marker). New test pins the statement order. Worker suite 49/49, typecheck clean.
|
@codex review New head c4327f3 fixes both P2 rounds on the deletion path: the tombstone is now written before the row DELETE (order pinned by a new test), closing the resurrection window in the non-transactional batch. Re-requesting review of the current head. (Queue worker lane code-c, task 14908.) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4327f3c23
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| sql: `UPDATE ${table} SET latest_agent_note_id = NULL, | ||
| latest_agent_note_url = NULL, mirrored_at = ? | ||
| WHERE repo = ? AND number = ? AND latest_agent_note_id = ?`, |
There was a problem hiding this comment.
Retain deletion evidence for agent-note comments
If an agent note's deleted delivery is processed before a delayed or redelivered created/edited delivery for the same comment, the latter restores a pointer to the deleted note. The fresh evidence is that this clear-to-NULL path erases the ordering state: the subsequent pointer update accepts the old note through latest_agent_note_id IS NULL, independently of whether its older comment count is rejected. The issue-level tombstone cannot prevent this because the parent issue still exists. Retain a per-comment deletion marker or equivalent version state and consult it before assigning either pointer field.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in fe93f71. The deleted delivery now also records the comment id in a new github_mirror_deleted_notes table (repo, number, comment_id), and both pointer CASE assignments (id and url) refuse any id carrying a marker — the NOT EXISTS check is inside the UPDATE statement itself, following the tombstone-guard pattern, so it is atomic with the assignment it guards and a delayed created/edited redelivery of the deleted comment can no longer resurrect the pointer through the latest_agent_note_id IS NULL branch. A genuinely recreated note always carries a new, higher comment id, so a marker can never suppress a live note.
Regression coverage: new test "a deleted note leaves a marker the pointer CASE consults (Codex P2)" asserts the marker insert, the shipped DDL, and the guard's presence in the pointer update; the creation-order test's bind count was updated for the two new guard binds. Suite at fe93f71: 54/54 vitest pass, tsc clean (the earlier 53/53 run at da41263 plus this fix).
|
@codex review Re-review requested for head c4327f3. The four findings from the previous round (mirror.ts: bulk-cursor fall-through on batch conflict, stale updated_at overwrite, deleted_at resurrection by out-of-order delivery, unfiltered issues/pull_request action handling) were fixed in this head per the replies on each thread. Please verify the fixes and re-check the full diff. |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review The branch was refreshed with a merge of current main (new head da41263; the mirror diff itself is unchanged). The worker suite re-verified locally at this head: 53/53 tests pass across 5 files (mirror.test.ts 18). Please complete the re-review of the current head, including the four earlier mirror.ts findings whose fixes landed in c4327f3. |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…gent-note pointer (#8580)
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
What
Fleet unification slice 2 (#8580), increment 1: the github-ci webhook Worker (#5693,
pkgs/github-ci/worker) now writes the GitHub mirror into the fleet-queue database.src/mirror.ts— mirror writers + pure payload builders:github_mirror_issues— title, body SHA-256 hash, state, labels, assignees, comments count, latest agent-note pointer, author, html_url, GitHub timestamps.github_mirror_pull_requests— the issue fields plus merged, draft, head sha/ref, base ref.github_mirror_meta— per-repo staleness readout:last_webhook_at/last_webhook_eventstamped on every mirrored delivery;last_backfill_atis reserved for the backfill/repair sweep.mirror.sql. Writes reuse the Worker's existing fleet-queue Turso credentials and the typed-args pipeline client — no new secrets.src/index.ts—issues/pull_requestdeliveries upsert the mirror row alongside the existing sink event + dirty watermark (the sink event now also carries the label name on label actions); newissue_commentbranch refreshes the mirror row's comments count and, when the comment carries theagent-note:v1marker, the latest agent-note pointer. Mirror write failures are fatal (500 → GitHub retries), matching the ci_events policy.test/mirror.test.ts(builders + fetch-mocked pipeline assertions) and two routing tests intest/worker.test.ts. Full worker suite: 39/39 pass;tsc --noEmitclean; prettier clean.Doctrine
The mirror is a read model: rebuildable from GitHub at any time, never a second truth. Staleness is reported (
github_mirror_meta), never gated on, per the #8575 ruling. README documents this.Remaining for #8580 (sequenced follow-on, tracked on the issue)
Deploy the Worker → #5693 webhook cutover (the Worker is dark until a repo webhook points at it) → live test issue/PR proof → backfill/repair sweep (stamps
last_backfill_at) → fleet-tool staleness readout → the 1-hour kill-and-restore acceptance test.Refs #8580, #8575, #5693.